package com.app.services.impl;

import com.app.common.SystemConstant;
import com.app.mapper.UserMapper;
import com.app.model.UserModel;
import com.app.services.LogonService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LogonServiceImpl implements LogonService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Result logon(String mobile, String code, Integer type) {

        String sql = "SELECT * FROM tb_msg_identifiy WHERE mi_mobile='" + mobile + "' AND mi_idenCode = '" + code + "'";
        List<Map<String, Object>> identifiylist_maps = jdbcTemplate.queryForList(sql);
        if (identifiylist_maps == null && identifiylist_maps.size() == 0) {
            return Result.success(405);
        }
        UserModel userModel = new UserModel();
        userModel.setMobile(mobile);
        userModel.setUserName(mobile);
        userModel.setCrtTime(CommonHelp.getNowTimestamp().toString());
        userModel.setCRegisterState(0);
        userModel.setFaceUrl(SystemConstant.DEFAULT_FACE_URL);
        userMapper.insert(userModel);
        return Result.success(userModel);
    }
}
